//
//  AllBuilding.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/26.
//  Copyright © 2020 mqd. All rights reserved.
//

#include "list.hpp"

AllBuilding::AllBuilding(int n):num(n){
    buildings = new Building[n];
    for(int i=0;i<n;i++)
        buildings[i].init(i+1);
}
void AllBuilding::autoDistribute(){
    for(int i=0;i<num;i++){
        buildings[i].autoDistribute(i+1);
    }
}

bool AllBuilding::autoDistributeOne(Student *stu){
    if (!stu) return 0;
    for(int i=0;i<num;i++){
        if (buildings[i].autoDistributeOne(stu)) return 1;
    }
    return 0;
}

bool AllBuilding::manualDistributeOne(Student *stu, int *room){
    if (!stu) return 0;
    if (room[0]<0 || room[0]>num) return 0;
    return buildings[room[0]].manualDistributeOne(stu, room[1], room[2]);
}
bool AllBuilding::find(std::string& s){
    int room[3];
    toRoom(s, room);
    
    if (room[0]<0 || room[0]>=num) return 0;
    return buildings[room[0]].find(room[1],room[2]);
}

bool AllBuilding::delOne(Student *stu){
    if (!stu) return 0;
    return buildings[stu->getBuildingId()-1].delOne(stu);
}
